package com.sz.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sz.mapper.ProblemMapper;
import com.sz.model.PageBean;
import com.sz.model.QuestionAnswer;
import com.sz.service.IPageBeanAnswer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PageBeanAnswerImpl implements IPageBeanAnswer {
    @Autowired
    private ProblemMapper problemMapper;
    @Override
    public PageBean<QuestionAnswer> getAllAnswer(int index, int size, int kid) {
        PageHelper.startPage(index, size); // 开始分页;
        List<QuestionAnswer> list = problemMapper.getAllAnswer(kid);
        Page<QuestionAnswer> plist = (Page<QuestionAnswer>) list;
        PageBean<QuestionAnswer> pb = new PageBean<>(
                plist.getTotal(),
                plist.getResult(),
                plist.getPageSize(),
                plist.getPages(),
                plist.getPageNum()
        );
        return pb;
    }

    @Override
    public PageBean<QuestionAnswer> getAnswer(int index,int size,String answer) {
        PageHelper.startPage(index, size); // 开始分页;
        List<QuestionAnswer> list = problemMapper.getAnswer(answer);
        Page<QuestionAnswer> plist = (Page<QuestionAnswer>) list;
        PageBean<QuestionAnswer> pb = new PageBean<>(
                plist.getTotal(),
                plist.getResult(),
                plist.getPageSize(),
                plist.getPages(),
                plist.getPageNum()
        );
        return pb;
    }
}
